import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:member_center_sdk_example/components/count_button.dart';
import 'package:member_center_sdk_example/components/loading_button.dart';

import 'action.dart';
import 'state.dart';

Widget buildView(
    SetPasswordBySmsState state, Dispatch dispatch, ViewService viewService) {
  return Scaffold(
      appBar: AppBar(
        title: const Text('设置密码'),
      ),
      body: _buildBody(state, dispatch, viewService));
}

Widget _buildBody(
    SetPasswordBySmsState state, Dispatch dispatch, ViewService viewService) {
  return Container(
    child: Column(
      children: <Widget>[
        Container(
          child: Row(
            children: <Widget>[
              Expanded(
                child: TextField(
                  controller: state.codeController,
                  keyboardType: TextInputType.number,
                  inputFormatters: <TextInputFormatter>[
                    WhitelistingTextInputFormatter.digitsOnly
                  ],
                  decoration:
                  InputDecoration(icon: Icon(Icons.sms), labelText: "验证码"),
                ),
              ),
              CountButton("发送", state.remainSeconds, () {
               dispatch(SetPasswordBySmsActionCreator.onSendSmsAction());
              }),
            ],
          ),
          padding: EdgeInsets.all(20),
        ),
        Container(
          padding: EdgeInsets.all(20),
          child: TextField(
            controller: state.passwordController,
            decoration:
            InputDecoration(icon: Icon(Icons.lock), labelText: "新密码"),
          ),
        ),
        new Container(
          child: LoadingButton("设置密码", state.isLoading, () {
           dispatch(SetPasswordBySmsActionCreator.onSetPasswordAction());
          }),
        ),
      ],
    ),
  );
}
